<?php

if (!defined('access')) {
    echo 'You cannot access this file directly.';
    exit();
}
$file_type = Array('asf', 'avi', 'dat', 'divx', 'flv', 'img', 'iso', 'm1v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm4v', 'mkv', 'mov', 'mp4', 'mpg', 'mts', 'qt', 'rm', 'rmp4', 'rmvb', 'tp', 'trp', 'ts', 'vob', 'wmv', 'mp3', 'wav', 'm3u', 'pls', 'xspf', 'jpg', 'png', 'jpeg', 'gif', 'bmp', '3gp', 'm4a', 'flac', 'ogg');
$vid_thumb = "/usr/local/etc/www/Jukebox/images/video_s.png";
$pls_thumb = "/usr/local/etc/www/Jukebox/images/playlist.png";
$fld_thumb = "/usr/local/etc/www/Jukebox/images/folder_s.png";
$mp3_thumb = "/usr/local/etc/www/Jukebox/images/music.png";
$sub_thumb = "/usr/local/etc/www/Jukebox/images/subtitles.png";
$img_thumb = "/usr/local/etc/www/Jukebox/images/images_s.png";
$dirs = "";
$files = "";
$show_subs = FALSE;
$sub_language = "ro";
if($show_subs){
    array_push($file_type, "srt", "sub");
}
if ($arg2 != null) {
    $output = '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	
	<bookmark>Samba login</bookmark>

<mediaDisplay 	
	name=onePartView
	itemPerPage=3
	viewAreaXPC=15
	viewAreaYPC=18
	viewAreaWidthPC=60
	viewAreaHeightPC=50

	itemXPC=15
	itemYPC=34
	itemWidthPC=35
	itemHeightPC=10
	itemImageXPC=15
	itemImageYPC=34.0
	itemImageWidthPC=35
	itemImageHeightPC=12.1

	imageFocus=""

	sideColorRight=-1:-1:-1
	sideColorLeft=-1:-1:-1
	sideColorTop=-1:-1:-1
	sideColorBottom=-1:-1:-1
	backgroundColor=-1:-1:-1
	focusBorderColor=-1:-1:-1
	unFocusBorderColor=-1:-1:-1
	itemBackgroundColor=-1:-1:-1
	showHeader="no"
	showDefaultInfo="no"
>
<backgroundDisplay>
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100 useBackgroundSurface=yes>
		./setup_menu/image/setup_popup_bg.fsp
	</image>
</backgroundDisplay>
<text offsetXPC=8.8 offsetYPC=5 widthPC=83.5 heightPC=18.4 fontSize=18 align=center backgroundColor=-1:-1:-1 foregroundColor=255:255:255 >
	<script>
		pageTitle;
	</script>
</text>
	<text redraw="yes" offsetXPC=50 offsetYPC=35 widthPC=30 heightPC=8 fontSize=16 backgroundColor=-1:-1:-1 >
	  <script>Username;</script>
	</text>
	<text redraw="yes" offsetXPC=50 offsetYPC=45 widthPC=30 heightPC=8 fontSize=16 backgroundColor=-1:-1:-1 >
	  <script>Password;</script>
	</text>
	<itemDisplay>
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100 useBackgroundSurface=yes >
		<script>
			image = "";
			queryIndex = getQueryItemIndex();
			focusIndex = getFocusItemIndex();
			if (queryIndex == focusIndex) {
				image = "./setup_menu/image/398_focus.fsp";
			}
			image;
		</script>
	</image>
<text offsetXPC=5 offsetYPC=5 widthPC=90 heightPC=90 align=right fontSize=16 >
		<foregroundColor>
			<script>
				fgcolor = "255:255:255";
				queryIndex = getQueryItemIndex();
				focusIndex = getFocusItemIndex();
				if (queryIndex == focusIndex) {
					fgcolor = "0:153:255";
				}
				fgcolor;
			</script>
		</foregroundColor>
		<script>
			title = getItemInfo("title");
			title;
		</script>
	</text>
	</itemDisplay>
</mediaDisplay>

<onExit>
  arr = null;
  arr = pushBackStringArray(arr, Username);
  arr = pushBackStringArray(arr, Password);
  print("arr=",arr);
  writeStringToFile(optionsPath, arr);
 savesettings = getURL("");
</onExit>

<onEnter>
	infoStr = "Please Wait...";
  pageTitle = "Samba Login";
  optionsPath = getStoragePath("key")+"shares_login.dat";
  optionsArray = readStringFromFile(optionsPath);
    Username = getStringArrayAt(optionsArray, 0);
    Password = getStringArrayAt(optionsArray, 1);
		itemSize = getXMLElementCount("rss", "channel", "item");
		print("itemSize = ", itemSize);

		if(itemSize &gt; 0)
		{
			itemCount = 0;
      	
			while(1)
			{
				itemTitle  = getXMLText("rss", "channel", "item", itemCount, "title");
				print("itemTitle = ", itemTitle);
				itemTitleArray  = pushBackStringArray(itemTitleArray, itemTitle);
      	
				itemCount += 1;
				if(itemCount == itemSize)
				{
					break;
				}
			}
			setFocusItemIndex(0);
			setItemFocus(0);
			redrawDisplay();
		}
</onEnter>

<channel>
  <title> Samba Login </title>

  <item>
    <title>Username:</title>
    <onClick>
    <script>
    username = getInput();
	if (username != null)
	{
    Username = username;
    }
    null;
    </script>
    </onClick>
  </item>

  <item>
    <title>Password:</title>
    <onClick>
    <script>
     password = getInput();
    if (password != null)
    {
     Password = password;
    }
    null;
    </script>
    </onClick>
  </item>
  
<item>
    <title>OK</title>
    <onClick>
     arr = null;
    arr = pushBackStringArray(arr, Username);
    arr = pushBackStringArray(arr, Password);
    print("arr=",arr);
    writeStringToFile(optionsPath, arr);
    postMessage("return");
    </onClick>
  </item>

</channel>

</rss>';
    echo $output;
} else {
    $source = urldecode($this->BrsFld);
    if ($arg1 != null) {
        $source = $arg1;
    }
    if ($source == null) {
        $source = '/tmp/ramfs/volumes';
        $dirs .= '<item>
	<title>Network</title>
	<link>' . $this->script_url . '?browser,ntwrk</link>
	<selection>Network</selection>
        <thumb>'.$fld_thumb.'</thumb>
        <pic></pic>
        <type>folder</type>
        </item>
        <item>
        <title>Favorites</title>
	<link>' . $this->script_url . '?browser,fav_l_browse</link>
	<selection>Favorites</selection>
        <pic></pic>
        <thumb>'.$fld_thumb.'</thumb>
        <type>folder</type>
        </item>';
    }
    if ($source == "ntwrk") {
        //find workgroups
        if ($this->Jukebox_Size == "2x6" || $this->Jukebox_Size == "3x8" || $this->Jukebox_Size == "sheetwall") {
            exec('/opt/bin/smbtree -N -D', $workgroups);
            $titlu = "Network";
            foreach ($workgroups as $workgroup => $name) {
                $dirs .= '<item>
            <title>' . $name . '</title>
            <link>' . $this->script_url . '?browser,ntwrk,' . $name . '</link>
            <pic></pic>
            <type>folder</type>
            <thumb>'.$fld_thumb.'</thumb>
            </item>';
            }
        } else {
            $titlu = "Network/".$this->Jukebox_Size;
            //find servers list
            $server = shell_exec('/opt/bin/smbtree -N -L -S');
            preg_match_all('~(\\\\)(\\\\)?(.*)?(\t+)~', $server, $matches);
            foreach ($matches[3] as $key => $value) {
                $key = $key + 1;
                $value = trim($value);
                $ip = shell_exec("/opt/bin/nmblookup " . $value);
                preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $ip, $matches);
                $dirs .= '
                <item>
                <title>' . $value . ' - ' . $matches[0][1] . '</title>
                <link>' . $this->script_url . '?browser,srv_br,' . $value . ',' . $matches[0][1] . '</link>
                <type>network</type>
                <thumb>'.$fld_thumb.'</thumb>
                </item>';
            }
        }
    } else if ($source == "srv_br") {
        //find server's shares
        $titlu = "Network/".$this->Jukebox_Size;
        $data_file = '/usr/local/etc/dvdplayer/shares_login.dat';
        $login_data = null;
        if (file_exists($data_file)) {
            $login_data = @file($data_file);
            $username = trim($login_data[0]);
            $password = trim($login_data[1]);
        } 
        //echo $username;
        //echo $password;
        if ($username != null || $password != null) {
            $list = shell_exec("/opt/bin/smbclient -N -L \\{$this->Jukebox_Size} -U {$username}%{$password} | awk '{print $1\"tipdir\"$2}'");
            if (preg_match('/sessiontipdirsetup/i', $list)) {
                $list = shell_exec("/opt/bin/smbclient -N -L \\{$this->Jukebox_Size} | awk '{print $1\"tipdir\"$2}'");
            }
        } else {
            $list = shell_exec("/opt/bin/smbclient -N -L \\{$this->Jukebox_Size} | awk '{print $1\"tipdir\"$2}'");
        }
        //echo $list;
        if (preg_match("/SharenametipdirType\s+---------tipdir----([\s\S]*?)tipdir\s+ServertipdirComment\s+---------/", $list, $s_list) == 0) {
            $this->file_browser(null, 'login');
            exit;
        }
        $dir_list = preg_split("/[\s]+/", trim($s_list[1], "\n"));
        foreach ($dir_list as $dir_type) {
            $d_type = preg_split("/tipdir/", $dir_type);
            if (preg_match('/Error/i', $d_type[0])) {
                $this->file_browser(null, 'login');
            }
            if ($d_type[1] == 'Disk') {
                $dirs .= '<item>
                <title>' . $d_type[0] . '</title>
                <link>' . $this->script_url . '?browser,fld_mnt,' . $this->item_pos . ',' . $d_type[0] . '</link>
                <type>network</type>
                <thumb>'.$fld_thumb.'</thumb>
                </item>';
                // echo "Nume: ". $d_type[0] . " --- Tip : " . $d_type[1] . "<br>";
            }
        }
    } else if ($source == "fld_mnt") {
        $dir = "/tmp/mount/network";
        if (!is_dir($dir)) {
            shell_exec("mkdir -p {$dir}");
        } else {
            shell_exec("/opt/bin/umount.cifs -n {$dir}");
        }
        $data_file = '/usr/local/etc/dvdplayer/shares_login.dat';
        $login_data = null;
        if (file_exists($data_file)) {
            $login_data = file($data_file);
            $username = trim($login_data[0]);
            $password = trim($login_data[1]);
        }
        if ($username != null || $password != null) {
            $mnt = shell_exec("/opt/bin/mount.cifs  '//$this->Jukebox_Size/$this->item_pos/' $dir/ -o username=$username,password=$password,iocharset=utf8");
            if (preg_match('/Permission denied/i', $mnt)) {
                shell_exec("/opt/bin/mount.cifs  '//$this->Jukebox_Size/$this->item_pos/' $dir/ -o guest,iocharset=utf8");
            }
        } else {
            shell_exec("/opt/bin/mount.cifs  '//$this->Jukebox_Size/$this->item_pos/' $dir/ -o guest,iocharset=utf8");
        }
        //echo "/tmp/usbmounts/sda3/mount.cifs  //{$this->item_pos}/$this->item_pos/ {$dir}/ -o guest";
        //$source = '/tmp/mnt/network';
        $this->file_browser($dir);
        //new SRJG(browser,'/tmp/mnt/network');
    } else if ($source == "fav_l_browse") {
        $this->db->exec("CREATE TABLE IF NOT EXISTS favorites (ID TEXT UNIQUE, fav TEXT)");
        $results = $this->db->query("SELECT fav FROM favorites");
        while($read = $results->fetchArray()){
            $dirs .='<item>
                <title>' . $read['fav'] . '</title>';
            if(is_dir($read['fav'])){
            $dirs .=    '<link>' . $this->script_url . '?browser,' . urlencode($read['fav']) . '</link>
            <type>folder</type>
            '; }
            $dirs .='<selection>'.urlencode($read['fav']).'</selection>
                <thumb>'.$fav_thumb.'</thumb>
                    <fav_check>yes</fav_check>
                    </item>';
        }
    } else {
        if ($this->BrsFld == "fld_mnt"){
            $titlu = "Network/" . $this->Jukebox_Size;
        }
        else {
        $titlu = @str_replace(array('/tmp/ramfs/volumes/', '/tmp/mount/network/'), array('', 'Network/'), @htmlspecialchars($this->BrsFld));
        }
            if ($source == "search") {
        $search_path = $this->Jukebox_Size;
        $search_item = $this->item_pos;
        $source = $search_path;
        $searches = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($search_path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY);
        foreach($searches as $found) {
            if (preg_match("/$search_item/i", pathinfo($found)['filename'])) {
            $name[] = $found;
            }
        }
            }
            else {
        $escapedBracketPath = str_replace('[', '\[', $source);
        $escapedBracketPath = str_replace(']', '\]', $escapedBracketPath);
        $escapedBracketPath = str_replace('\[', '[[]', $escapedBracketPath);
        $escapedBracketPath = str_replace('\]', '[]]', $escapedBracketPath);
        foreach (glob($escapedBracketPath . '/*') as $dir) {
            $name[] = $dir;
        }
            }
//print_r($name);
        if (!empty($name)) {
            natcasesort($name);
            //sort($name, SORT_NATURAL | SORT_FLAG_CASE);
            foreach ($name as $dir) {
                $dir1 = str_replace($source . '/', '', $dir);
                $dir = str_replace('//', '/', $dir);
                $specialdir1 = str_replace(array(" "),array("&#32;"),htmlspecialchars(str_replace($source . '/', '', $dir)));
                if (is_dir($dir)) {
                    $dirs .= '
	<item>
	<title>' . $specialdir1 . '</title>
	<link>' . $this->script_url . '?browser,' . urlencode(htmlspecialchars($dir)) . '</link>
	<selection>' . urlencode($dir) . '</selection>
	<sel>' . urlencode($dir) . '</sel>
        <pic>' . htmlspecialchars($dir) . '/folder.jpg' . '</pic>
        <thumb>'.$fld_thumb.'</thumb>
        <type>folder</type>
        </item>';
                } else {
                    $parts = pathinfo($dir);
                    $dir = $parts['dirname'];
                    if (In_Array(strtolower($parts['extension']), array_map('strtolower', $file_type)) == true) {
                        if ($source != '/tmp/ramfs/volumes') {
                            switch ($parts['extension']) {
                                case (preg_match('/m3u/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            url = "' . $dir . '/' . $dir1 . '";
                            print("onClick |*****|",url);
                            showIdle();
                            doModalRss("http://127.0.0.1/Jukebox/srjg/m3u.class.php?file="+ urlEncode(url));
                            null;
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <type>playlist</type>
                            <thumb>'.$pls_thumb.'</thumb>
                            </item>
                            ';
                                    break;
                                case (preg_match('/xspf/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            url = "' . $dir . '/' . $dir1 . '";
                            print("onClick |*****|",url);
                            showIdle();
                            doModalRss("http://127.0.0.1/Jukebox/srjg/xspf.php?file="+ urlEncode(url));
                            null;
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <type>playlist</type>
                            <thumb>'.$pls_thumb.'</thumb>
                            </item>
                            ';
                                    break;
                                case (preg_match('/pls/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            url = "' . $dir . '/' . $dir1 . '";
                            print("onClick |*****|",url);
                            showIdle();
                            doModalRss("http://127.0.0.1/Jukebox/srjg/pls.php?file="+ urlEncode(url));
                            null;
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <type>playlist</type>
                            <thumb>'.$pls_thumb.'</thumb>
                            </item>
                            ';
                                    break;
                                case (preg_match('/mp3|m4a|flac|wav|ogg/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $audio_list[] =  $dir . '/' . $parts['filename'] . '.' . $parts['extension'] ;
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            url = "' . $dir . '/' . $dir1 . '";
                            print("onClick |*****|",url);
                            showIdle();
                            doModalRss("http://127.0.0.1/Jukebox/audioRenderer.php?' . urlencode($dir . '/' . $dir1) . ',' . urlencode($parts['filename']) . '");
                            null;
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . htmlspecialchars($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <type>music</type>
                            <thumb>'.$mp3_thumb.'</thumb>
                            </item>
                            ';
                                    break;
                                case (preg_match('/(jpg|jpeg|gif|bmp|png)/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $photo_list[] =  $dir . '/' . $parts['filename'] . '.' . $parts['extension'] ;
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            doModalRss("http://127.0.0.1/Jukebox/srjg/photo_view.php?file=' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '");
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <thumb>'.$img_thumb.'</thumb>
                            <sel>'.urldecode($dir . '/' . $parts['filename'] . '.' . $parts['extension']).'</sel>
                            <type>picture</type>
                            </item>
                            ';
                                    break;
                                case (preg_match('/(srt|sub)/i', $parts['extension']) ? $parts['extension'] : !$parts['extension']);
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            doModalRss("http://127.0.0.1/Jukebox/srjg/sub_preview.php?file=' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '");
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '</selection>
                            <thumb>'.$sub_thumb.'</thumb>
                            <type>subtitle</type>
                            </item>
                            ';
                                    break;
                                default :
                                    $video_list[] = $dir . '/' . $parts['filename'] . '.' . $parts['extension'];
                                    $files .= '
                            <item>
                            <title>' . $specialdir1 . '</title>
                            <onClick>
                            showIdle();
                            doModalRss("'. $this->script_url . '?videorender,' . urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension']) . '");
                                null;
                            cancelIdle();
                            </onClick>
                            <path>' . $dir . '</path>
                            <ext>'.$parts['extension'].'</ext>
                            <file>' . $parts['filename'] . '</file>
                            <selection>' . htmlspecialchars(urlencode($dir . '/' . $parts['filename'] . '.' . $parts['extension'])) . '</selection>
                            <sel>'.urldecode($dir . '/' . $parts['filename'] . '.' . $parts['extension']).'</sel>
                            <type>video</type>
                            <thumb>'.$vid_thumb.'</thumb>
                            </item>';
                                    break;
                            }
                        }
                    }
                }
            }
            //session_start();
            //$_SESSION['list'] = $list;
            //$photo_list ? file_put_contents('/tmp/photo_list.dat', implode(PHP_EOL, $photo_list)) : false;
            if ($photo_list){
                file_put_contents('/tmp/photo_list.dat', implode(PHP_EOL, $photo_list));
                file_put_contents('/tmp/photo_count.dat', count($photo_list));
            }
            $video_list ? file_put_contents('/tmp/video_list.dat', implode(PHP_EOL, $video_list)) : false;
        }
    }
    //$titlu = ($source == "ntwrk") ? (($this->Jukebox_Size == "2x6" || $this->Jukebox_Size == "3x8" || $this->Jukebox_Size == "sheetwall") ? "Network" : "Network/".$this->Jukebox_Size ) : ($source == "srv_br" ? "Network/".$this->Jukebox_Size : ( ($source == "fld_mnt") ? $this->Jukebox_Size : @str_replace('/tmp/ramfs/volumes/', '', @htmlspecialchars($this->BrsFld))));
    $output = '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<bookmark>' . $this->BrsFld . '</bookmark>
    
<onEnter>
redrawDisplay();
url="' . $dir . '/' . $parts['filename'] . '.' . $parts['extension'] . '";
lang="'.$sub_language.'";
</onEnter>
<mediaDisplay
	name=onePartView
        itemPerPage=10
	viewAreaXPC=0
	viewAreaYPC=0
	viewAreaWidthPC=100
	viewAreaHeightPC=100
	itemXPC=10
	itemYPC=30
	itemWidthPC=80
	itemHeightPC=6
	itemImageWidthPC="0"
	itemImageHeightPC="0"
	backgroundColor=-1:-1:-1
	itemBackgroundColor=-1:-1:-1
	showHeader="no"
	showDefaultInfo="no"
	rollItems="no"
	forceRedrawItems="no"
>
<idleImage>image/POPUP_LOADING_01.png</idleImage>
        <idleImage>image/POPUP_LOADING_02.png</idleImage>
        <idleImage>image/POPUP_LOADING_03.png</idleImage>
        <idleImage>image/POPUP_LOADING_04.png</idleImage>
        <idleImage>image/POPUP_LOADING_05.png</idleImage>
        <idleImage>image/POPUP_LOADING_06.png</idleImage>
        <idleImage>image/POPUP_LOADING_07.png</idleImage>
        <idleImage>image/POPUP_LOADING_08.png</idleImage>
<backgroundDisplay >
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100 useBackgroundSurface="yes">
		./setup_menu/image/setup_popup_bg.fsp
	</image>
</backgroundDisplay>
<text redraw="yes" offsetXPC="80" offsetYPC="21" widthPC="10" heightPC="6" fontSize="17" foregroundColor="255:255:255" useBackgroundSurface="yes">
		  <script>sprintf("%s / ", getFocusItemIndex()-(-1))+getPageInfo("itemCount");</script>
		</text>
<text redraw=yes offsetXPC=5 offsetYPC=5 widthPC=90 heightPC=20 fontSize=23 align=center >
	File Browser
</text>
<text redraw=yes offsetXPC=10 offsetYPC=16 widthPC=85 heightPC=17 fontSize=17 align=left >
	' . $titlu . '
</text>
<text redraw="yes" offsetXPC=90 offsetYPC=29 widthPC=1 heightPC=60 backgroundColor=0:0:0>
	  <script>bar;</script>
	</text>
	<text redraw="yes" offsetXPC=90.3 offsetYPC=29 widthPC=.5 heightPC=60 backgroundColor=30:30:30>
	  <script>bar;</script>
	</text>
	<text redraw="yes" offsetXPC=90 offsetYPC=29 widthPC=1 heightPC=60 backgroundColor=130:130:30>
	  <script>bar;</script>
	  <heightPC>
	    <script>
	      60 / getPageInfo("itemCount");
	    </script>
	  </heightPC>
	  <offsetYPC>
	    <script>
	      focus = getFocusItemIndex();
	      29 + 60 * focus / getPageInfo("itemCount");
	    </script>
	  </offsetYPC>
	</text>
<itemDisplay>
	<!-- clear background -->
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100 useBackgroundSurface="yes"/>
	<!-- draw foreground -->
	<image offsetXPC=4.5 offsetYPC=3 widthPC=95.5 heightPC=100>
		<script>
			image = "";
			queryIndex = getQueryItemIndex();
			focusIndex = getFocusItemIndex();
			if (queryIndex == focusIndex) {
				image = "./setup_menu/image/UI_Settings_Banner.png";
			}
			image;
		</script>
	</image>
	<text offsetXPC=4 offsetYPC=5 widthPC=95 heightPC=100 align=left fontSize=14>
		<script>
			getItemInfo("title");
		</script>
			  <foregroundColor>
  				<script>
  					idx = getQueryItemIndex();
  					focus = getFocusItemIndex();
  			    if(focus==idx) "255:255:255"; else "140:140:140";
  				</script>
			  </foregroundColor>
	</text>
        <image offsetXPC=94 offsetYPC=10 widthPC=5 heightPC=80 align=right backgroundColor=-1:-1:-1>
        <script>
        path = getItemInfo(-1, "path");
        file = getItemInfo(-1, "file");
        ext = getItemInfo(-1, "ext");
        titlu1 = getItemInfo(-1, "title");
        check = readStringFromFile(path+"/."+file);
        check2 = readStringFromFile(path+"/"+titlu1+".seen");
        if (check != null || check2 != null) "/usr/local/etc/www/Jukebox/images/checkmark_s.png";
        </script>
        </image>
        <image offsetXPC=0 offsetYPC=10 widthPC=5 heightPC=80 align=right backgroundColor=-1:-1:-1>
        <script>
        thumb = getItemInfo(-1, "thumb");
        thumb;
        </script>
        </image>
        <filesettings>
	<mediaDisplay>
		<onEnter>
			popupHeader = "Edit menu";
			popupMessageSize = 1;
			popupMessages = getEnv("popup");
			popupOptionSize = 8;
                        if(getEnv("type") == "video"){
                        popupOptionSize = 9;
                        read = readStringFromFile(getEnv("edit_path")+".seen");
                        if(read != NULL) {
                        popupOptions = pushBackStringArray(popupOptions, "Mark as Unseen");
                        }
                        else {
                        popupOptions = pushBackStringArray(popupOptions, "Mark as Seen");
                        }
                        popupOptions = pushBackStringArray(popupOptions, "Download Subtitle");
                        }
			popupOptions = pushBackStringArray(popupOptions, "Copy");
			popupOptions = pushBackStringArray(popupOptions, "Move");
                        popupOptions = pushBackStringArray(popupOptions, "Delete");
                        popupOptions = pushBackStringArray(popupOptions, "Rename");
                        if(getEnv("fav_env") == "yes"){
                        popupOptions = pushBackStringArray(popupOptions, "Remove Fav");
                        } else {
                        popupOptions = pushBackStringArray(popupOptions, "Add Fav"); }
                        unsetEnv("fav_env");
                        unsetEnv("edit_path");
                        unsetEnv("type");
		</onEnter>
	</mediaDisplay>
</filesettings>
<filesettings>
	<mediaDisplay>
		<onEnter>
			popupHeader = "Delete";
			popupMessageSize = 1;
			popupMessages = "Delete "+ getEnv("popup")+"?";
			popupOptionSize = 2;
			popupOptions = pushBackStringArray(popupOptions, "Yes");
			popupOptions = pushBackStringArray(popupOptions, "No");
                        unsetEnv("popup");
		</onEnter>
	</mediaDisplay>
</filesettings>
<sublang>
	<mediaDisplay>
		<onEnter>
			popupHeader = "Subtitle language";
			popupOptionSize = 2;
			popupOptions = pushBackStringArray(popupOptions, "Romanian");
			popupOptions = pushBackStringArray(popupOptions, "English");
		</onEnter>
	</mediaDisplay>
</sublang>
 <confirmation>
	<mediaDisplay>
		<onEnter>
			popupHeader = "Success";
			popupOptionSize = 1;
			popupOptions = pushBackStringArray(popupOptions, "OK");
		</onEnter>
	</mediaDisplay>
</confirmation>
</itemDisplay>
<onUserInput>

userInput = currentUserInput();
ret = "false";
itemCount = getPageInfo("itemCount");
if (userInput == "pagedown" || userInput == "pageup")
{
  idx = getFocusItemIndex();
  if (userInput == "pagedown")
  {
    idx -= -9;
    if(idx &gt;= itemCount)
      idx = itemCount-1;
  }
  else
  {
    idx -= 9;
    if(idx &lt; 0)
      idx = 0;
  }

  print("new idx: "+idx);
  setFocusItemIndex(idx);
	setItemFocus(idx);
  redrawDisplay();
  ret = "true";
}
else if (userInput == "menu") {
current = getFocusItemIndex();
popup = getItemInfo(current, "title");
edit_path = getItemInfo(current, "sel");
file_type = getItemInfo(current, "type");
setenv("type", file_type);
setenv("fav_env", getItemInfo(current, "fav_check"));
setenv("popup", popup);
setenv("edit_path", edit_path);
rss = "rss_file://./setup_menu/scripts/dynamicPopup.rss";
confirm = doModalRss(rss, "mediaDisplay", "itemDisplay", "filesettings", 0);
if ( confirm == "Delete" ){
sure = doModalRss(rss, "mediaDisplay", "itemDisplay", "filesettings", 1);
if (sure == "Yes") {
confirmation = getURL("'. $this->script_url . '?file_op,delete,"+edit_path);
if ( confirmation == "done") {
doModalRss(rss, "mediaDisplay", "itemDisplay", "confirmation", 0);
}
}
}
else if ( confirm == "Mark as Seen" ){
writeStringToFile(edit_path+".seen", "seen");
}
else if ( confirm == "Mark as Unseen" ){
deleteFile(edit_path+".seen");
}
else if ( confirm == "Add Fav" ){
confirm = getUrl("'. $this->script_url .'?add_fav,"+edit_path);
}
else if ( confirm == "Download Subtitle" ){
sub_lang = doModalRss(rss, "mediaDisplay", "itemDisplay", "sublang", 0);
    if ( sub_lang == "Romanian" ) {
        lang = "ro"; } 
    else if ( sub_lang =="English" ) {
        lang = "en"; }
confirm = doModalRss("'. $this->script_url .'?sub_download,"+edit_path+","+lang);
ret = "true";
null;
}
else if ( confirm == "Remove Fav" ){
confirm = getUrl("'. $this->script_url .'?rem_fav,"+edit_path);
}
else if ( confirm == "Copy" ){
confirm = doModalRss(rss, "mediaDisplay", "itemDisplay", "filesettings", 0);
}
ret = "true";
null;
}';
    $output .= '
else if (userInput == "six" || userInput == "6") {
seen_f = getItemInfo(-1, "selection");
read = readStringFromFile(seen_f+".seen");
if(read != null) {
deleteFile(seen_f+".seen");
}
else {
writeStringToFile(seen_f+".seen", "seen"); 
}
redrawDisplay();
ret = "true";
}
else if (userInput == "display") {
det_file = getItemInfo(-1, "selection");
type = getItemInfo(-1, "type");
info = doModalRss("http://127.0.0.1/Jukebox/det_info.php?file="+ det_file );
redrawDisplay();
ret = "true";
}
else if (userInput == "video_search") {
inputMovie=getInput("userName","doModal");
if (inputMovie != NULL) {
 doModalRss("' . $this->script_url . '?browser,search,'. $source. ',"+inputMovie);
}
redrawDisplay();
ret = "true";
}
ret;
</onUserInput>
</mediaDisplay>
<popupdialog>
<mediaDisplay>
<onEnter>
setFocusItemIndex(idx);
file_array = '. $video_list .';
</onEnter>
</mediaDisplay>
</popupdialog>
<channel>
<title>Browse for folder</title>';
    echo $output;
    echo $dirs;
    echo $files;
    $this->Footer(); 
}
